//------------------------------------------------------------
//  Filename: fusion_top.v
//   
//  Author  : wlduan@gmail.com
//  Revise  : 2016-09-26 12:41
//  Description: 
//   
//  Copyright (C) 2014, YRBD, Inc. 					      
//  All Rights Reserved.                                       
//-------------------------------------------------------------
//
`timescale 1ns/1ps
 
module FUSION_TOP  #(
    parameter integer C_S_AXI_DATA_WIDTH     = 32,
    parameter integer C_S_AXI_ADDR_WIDTH     = 16,
    parameter integer C_M_AXI_BURST_LEN      = 64,
    parameter integer C_M_AXI_ID_WIDTH       = 1,
    parameter integer C_M_AXI_ADDR_WIDTH     = 32,
    parameter integer C_M_AXI_DATA_WIDTH     = 32,
    parameter integer C_M_AXI_AWUSER_WIDTH   = 0,
    parameter integer C_M_AXI_ARUSER_WIDTH   = 0,
    parameter integer C_M_AXI_WUSER_WIDTH    = 0,
    parameter integer C_M_AXI_RUSER_WIDTH    = 0,
    parameter integer C_M_AXI_BUSER_WIDTH    = 0    
) ( 
    input  wire                                 REGS_AXI_ACLK,
    input  wire                                 REGS_AXI_ARESETN,
    input  wire [C_S_AXI_ADDR_WIDTH-1 : 0     ] REGS_AXI_AWADDR,
    input  wire [2 : 0                        ] REGS_AXI_AWPROT,
    input  wire                                 REGS_AXI_AWVALID,
    output wire                                 REGS_AXI_AWREADY,
    input  wire [C_S_AXI_DATA_WIDTH-1 : 0     ] REGS_AXI_WDATA,
    input  wire [(C_S_AXI_DATA_WIDTH/8)-1 : 0 ] REGS_AXI_WSTRB,
    input  wire                                 REGS_AXI_WVALID,
    output wire                                 REGS_AXI_WREADY,
    output wire [1 : 0                        ] REGS_AXI_BRESP,
    output wire                                 REGS_AXI_BVALID,
    input  wire                                 REGS_AXI_BREADY,
    input  wire [C_S_AXI_ADDR_WIDTH-1 : 0     ] REGS_AXI_ARADDR,
    input  wire [2 : 0                        ] REGS_AXI_ARPROT,
    input  wire                                 REGS_AXI_ARVALID,
    output wire                                 REGS_AXI_ARREADY,
    output wire [C_S_AXI_DATA_WIDTH-1 : 0     ] REGS_AXI_RDATA,
    output wire [1 : 0                        ] REGS_AXI_RRESP,
    output wire                                 REGS_AXI_RVALID,
    input  wire                                 REGS_AXI_RREADY,  
     
    //************* Read channel ***********  
    input  wire                                 VGA_AXI_ACLK,
    input  wire                                 VGA_AXI_ARESETN,   
    output wire [C_M_AXI_ID_WIDTH-1 : 0       ] VGA_AXI_ARID,
    output wire [C_M_AXI_ADDR_WIDTH-1 : 0     ] VGA_AXI_ARADDR,
    output wire [7 : 0                        ] VGA_AXI_ARLEN,
    output wire [2 : 0                        ] VGA_AXI_ARSIZE,
    output wire [1 : 0                        ] VGA_AXI_ARBURST,
    output wire                                 VGA_AXI_ARLOCK,
    output wire [3 : 0                        ] VGA_AXI_ARCACHE,
    output wire [2 : 0                        ] VGA_AXI_ARPROT,
    output wire [3 : 0                        ] VGA_AXI_ARQOS,
    output wire [C_M_AXI_ARUSER_WIDTH-1 : 0   ] VGA_AXI_ARUSER,
    output wire                                 VGA_AXI_ARVALID,
    input  wire                                 VGA_AXI_ARREADY,
    input  wire [C_M_AXI_ID_WIDTH-1 : 0       ] VGA_AXI_RID,
    input  wire [C_M_AXI_DATA_WIDTH-1 : 0     ] VGA_AXI_RDATA,
    input  wire [1 : 0                        ] VGA_AXI_RRESP,
    input  wire                                 VGA_AXI_RLAST,
    input  wire [C_M_AXI_RUSER_WIDTH-1 : 0    ] VGA_AXI_RUSER,
    input  wire                                 VGA_AXI_RVALID,
    output wire                                 VGA_AXI_RREADY,
    //************* Write channel ***********
    input  wire                                 CAMERA_AXI_ACLK,
    input  wire                                 CAMERA_AXI_ARESETN,
    output wire [C_M_AXI_ID_WIDTH-1 : 0       ] CAMERA_AXI_AWID,
    output wire [C_M_AXI_ADDR_WIDTH-1 : 0     ] CAMERA_AXI_AWADDR,
    output wire [7 : 0                        ] CAMERA_AXI_AWLEN,
    output wire [2 : 0                        ] CAMERA_AXI_AWSIZE,
    output wire [1 : 0                        ] CAMERA_AXI_AWBURST,
    output wire                                 CAMERA_AXI_AWLOCK,
    output wire [3 : 0                        ] CAMERA_AXI_AWCACHE,
    output wire [2 : 0                        ] CAMERA_AXI_AWPROT,
    output wire [3 : 0                        ] CAMERA_AXI_AWQOS,
    output wire [C_M_AXI_AWUSER_WIDTH-1 : 0   ] CAMERA_AXI_AWUSER,
    output wire                                 CAMERA_AXI_AWVALID,
    input  wire                                 CAMERA_AXI_AWREADY,
    output wire [C_M_AXI_DATA_WIDTH-1 : 0     ] CAMERA_AXI_WDATA,
    output wire [C_M_AXI_DATA_WIDTH/8-1 : 0   ] CAMERA_AXI_WSTRB,
    output wire                                 CAMERA_AXI_WLAST,
    output wire [C_M_AXI_WUSER_WIDTH-1 : 0    ] CAMERA_AXI_WUSER,
    output wire                                 CAMERA_AXI_WVALID,
    input  wire                                 CAMERA_AXI_WREADY,
    input  wire [C_M_AXI_ID_WIDTH-1 : 0       ] CAMERA_AXI_BID,
    input  wire [1 : 0                        ] CAMERA_AXI_BRESP,
    input  wire [C_M_AXI_BUSER_WIDTH-1 : 0    ] CAMERA_AXI_BUSER,
    input  wire                                 CAMERA_AXI_BVALID,
    output wire                                 CAMERA_AXI_BREADY,
    //-------------------------------------------------------- 
    input  wire                                 clk_24mhz,
    input  wire                                 clk_25mhz,
    input  wire                                 clk_100mhz,
    input  wire                                 a100m_resetn,
    input  wire                                 a25m_resetn,

    output wire [4:0]                           R, //RGB565 VGA Interface
    output wire [5:0]                           G,
    output wire [4:0]                           B,
    output wire                                 vga_de,
    output wire                                 vga_pclk,
    output wire                                 vga_h_sync,  
    output wire                                 vga_v_sync,

    output wire                                 SDIO_0_wp,
    output wire                                 vga_pwr_off,
    input  wire                                 vp_in,
    input  wire                                 vn_in, 
    input  wire                                 tp_in,
    input  wire                                 tn_in,  
              
    output wire [3:0]                           phase_l,
    output wire [3:0]                           phase_r,
    output wire [3:0]                           phase_x,
    output wire [3:0]                           phase_y,    
    
	input  wire                                 heat_touch  ,
    input  wire                                 hall_touch  ,
    input  wire                                 posl_touch  ,
    input  wire                                 posr_touch  ,

    output wire                                 gaoya       ,
    output wire                                 beep        ,
    output wire                                 heat        ,
    output wire                                 heat_ledon  ,

    output wire                                 dac_sdata   ,
    output wire                                 dac_sclk    ,
    output wire                                 dac_load    ,

    output wire                                 rtc_scl     ,
    inout  wire                                 rtc_sda     ,
	//-------------------------------------------------------- 
    input  wire                                 camera0_pclk, 
    input  wire [7:0]                           camera0_yuv , 
    input  wire                                 camera0_h_sync, 
    input  wire                                 camera0_v_sync, 
    output wire                                 camera0_pwrdown,
    output wire                                 camera0_resetn,
	output wire                                 camera0_xclk,

    output wire                                 camera0_sclk,
    inout  wire                                 camera0_sda ,

    input  wire                                 camera1_pclk, 
    input  wire [7:0]                           camera1_yuv , 
    input  wire                                 camera1_h_sync, 
    input  wire                                 camera1_v_sync, 
    output wire                                 camera1_pwrdown,
    output wire                                 camera1_resetn,
	output wire                                 camera1_xclk,
	
    output wire                                 camera1_sclk,
    inout  wire                                 camera1_sda ,

    output wire [15:0]                          camera0_cfgAddr,
    input  wire [23:0]                          camera0_cfgData,
    
    output wire [15:0]                          camera1_cfgAddr,
    input  wire [23:0]                          camera1_cfgData,
	//--------------------------------------------------------
    input  wire                                 pl_clk,
    output wire                                 pwr_ctrl,
    output wire                                 backlight_pwm,

    input  wire [31:0]                          hardware_version,
    input  wire [11:0]                          key_button,
    output wire                                 key_intr,
    
    output wire                                 fusion_proc_intr
);      
//--------------------------------------------------------
wire       resetn = a100m_resetn;
wire       video0_only        ;
wire       video1_only        ;
wire[31:0] video0_base_addr   ;
wire[31:0] video1_base_addr   ;
wire[31:0] menu_base_addr     ;
wire[31:0] data_flow_err      ;    

wire[7:0]  touch_status       ; 
wire[31:0] pix_cnt            ;
wire[7:0 ] menu_alpha         ;
wire[7:0 ] backlight_pwm_ctnr ;

wire       mm_disp_en         ;
wire       mm_menu_en         ;
wire       mm_bar_hide        ;

wire       xadc_init          ;
wire[15:0] temp_value         ;   
wire[15:0] vpin_value         ;   
wire[15:0] vint_value         ;   
wire[15:0] vaux_value         ;   
wire[15:0] vtmp_value         ;  

wire[31:0] motor_speed        ;
wire[31:0] motor_ctrl_l       ;
wire[31:0] motor_ctrl_r       ;
wire[31:0] motor_ctrl_x       ;
wire[31:0] motor_ctrl_y       ;
 
wire[31:0] fusion_push_state  ; 
wire[31:0] fusion_proc_state  ; 
wire[31:0] fusion_base_x      ; 
wire[7:0]  fusion_pix_black   ; 
wire[31:0] fusion_push_ctrl   ; 
wire[7:0]  fusion_face_sens   ; 
wire[7:0]  fusion_edge_sens   ; 
wire[11:0] fusion_fast_l_x    ; 
wire[11:0] fusion_slow_l_x    ; 
wire[11:0] fusion_fast_r_x    ; 
wire[11:0] fusion_slow_r_x    ; 

wire[31:0] fiber_push_status  ;
wire[31:0] fiber_aux_ctrl     ;
 
wire       force_pause_l      ;
wire       force_pause_r      ;

wire[31:0] motor_move_l       ;
wire[31:0] motor_move_r       ;

wire       slow_clk30k_out    ; 
wire       slow_clk1k_out     ; 

wire[11:0] cpu_mem_addrb      ;
wire[31:0] cpu_mem_doutb      ;
wire       cpu_mem_ready0     ;
wire       cpu_mem_ready1     ;

wire[11:0] keyout             ; 
wire[31:0] gaoya_time         ; 
wire[7 :0] gaoya_force        ; 
wire[31:0] gaoya_ctrl_time    ; 
wire[7:0]  gaoya_ctrl_force   ; 
wire[31:0] fusion_force_cfg   ; 
wire[31:0] fusion_time_cfg    ; 

wire[15:0] heat_time          ; 
wire[15:0] heat_speed         ; 
wire       heat_mode          ; 
wire       heat_status        ;
wire       heat_test          ; 
    
wire[31:0] beep_cntr          ; 
wire[31:0] tone_divider       ; 

wire[31:0] rtc_ctrl           ;
wire[15:0] rtc_data_read      ;
wire       rtc_trans_over     ;
 
wire       load_time          ;
wire[31:0] pcf8563_date       ;
wire[31:0] pcf8563_time       ;
wire[31:0] local_date         ;
wire[31:0] local_time         ;

wire[31:0] eeprom_ctrl        ; 
wire[15:0] eeprom_data_read   ; 
wire       eeprom_trans_over  ; 


wire       camera0_video_en   ;
wire[23:0] camera0_dsp_ctrl   ;  
wire[31:0] camera0_base_addr  ;
wire       camera0_base_update;

wire[31:0] camera0_ctrl       ;
wire[15:0] camera0_data_read  ;
wire       camera0_trans_over ;

wire[31:0] camera0_param      ; 
wire[31:0] camera0_error      ; 
wire[15:0] camera0_x_scaler   ;
wire[15:0] camera0_y_scaler   ;
wire[15:0] camera0_x_org_cnt  ; 
wire[15:0] camera0_y_org_cnt  ; 
wire[31:0] camera0_pwr_ctrl   ;

wire[31:0] calibera_edge_x    ;
wire[31:0] calibera_edge_y    ;
wire[31:0] engineer_edge_x    ;
wire[31:0] engineer_edge_y    ;
wire[31:0] engineer_bright    ;

wire       camera1_video_en   ;
wire[23:0] camera1_dsp_ctrl   ;  
wire[31:0] camera1_base_addr  ;
wire       camera1_base_update;

wire[31:0] camera1_ctrl       ;
wire[15:0] camera1_data_read  ;
wire       camera1_trans_over ;

wire[31:0] camera1_param      ;
wire[31:0] camera1_error      ;  
wire[15:0] camera1_x_scaler   ;
wire[15:0] camera1_y_scaler   ;
wire[15:0] camera1_x_org_cnt  ; 
wire[15:0] camera1_y_org_cnt  ; 
wire[31:0] camera1_pwr_ctrl   ;

wire[15:0] camera0_cfg_state  ;
wire[15:0] camera1_cfg_state  ;

wire       soft_pwr_off       ;
wire       force_pwr_off      ;
wire[7:0]  disp_graym         ;

wire[32:0] coproc0_din        ;
wire       coproc0_wr_en      ;

wire[32:0] coproc1_din        ;
wire       coproc1_wr_en      ;

wire       camera0_wr_en      ; 
wire[32:0] camera0_din        ; 

wire       camera1_wr_en      ; 
wire[32:0] camera1_din        ; 

wire       pwr_touch           = key_button[11];
wire[10:0] pl_keys             = key_button[10:0]; 
wire[10:0] plh_keys           ; 
wire[10:0] func_keys          ;

wire       pl_24mhz           ;
wire       pl_175mhz      ;
wire       pl_24mhz_lock      ;
//--------------------------------------------------------
assign camera0_xclk = pl_24mhz;
assign camera1_xclk = pl_24mhz;
wire   c_resetn     = pl_24mhz_lock;
//assign camera1_xclk = clk_24mhz;
//assign camera0_xclk = clk_24mhz;
//wire  c_resetn      = a100m_resetn;
//--------------------------------------------------------
clk_wiz_pixl  clk_wiz_pixl_inst0(
    .clk_in_25m   ( pl_clk    ),
    .clk_out_24m  ( pl_24mhz  ),
    .clk_out_175m ( pl_175mhz ),
    
    .reset        ( ~a100m_resetn  ),
    .locked       ( pl_24mhz_lock )
);

//--------------------------------------------------------
fusion_S00_AXI #(
    .FRAME_BUFFER_BASE  ( 'h30000000         ) ,
    .FRAME_BUFFER_SIZE  ( 'h00200000         ) ,
    .C_S_AXI_DATA_WIDTH ( C_S_AXI_DATA_WIDTH ) ,
    .C_S_AXI_ADDR_WIDTH ( C_S_AXI_ADDR_WIDTH )
) fusion_S00_AXI_inst0(
    .REGS_AXI_ACLK          ( REGS_AXI_ACLK          ) ,
    .REGS_AXI_ARESETN       ( REGS_AXI_ARESETN       ) ,
    .REGS_AXI_AWADDR        ( REGS_AXI_AWADDR        ) ,
    .REGS_AXI_AWPROT        ( REGS_AXI_AWPROT        ) ,
    .REGS_AXI_AWVALID       ( REGS_AXI_AWVALID       ) ,
    .REGS_AXI_AWREADY       ( REGS_AXI_AWREADY       ) ,
    .REGS_AXI_WDATA         ( REGS_AXI_WDATA         ) ,
    .REGS_AXI_WSTRB         ( REGS_AXI_WSTRB         ) ,
    .REGS_AXI_WVALID        ( REGS_AXI_WVALID        ) ,
    .REGS_AXI_WREADY        ( REGS_AXI_WREADY        ) ,
    .REGS_AXI_BRESP         ( REGS_AXI_BRESP         ) ,
    .REGS_AXI_BVALID        ( REGS_AXI_BVALID        ) ,
    .REGS_AXI_BREADY        ( REGS_AXI_BREADY        ) ,
    .REGS_AXI_ARADDR        ( REGS_AXI_ARADDR        ) ,
    .REGS_AXI_ARPROT        ( REGS_AXI_ARPROT        ) ,
    .REGS_AXI_ARVALID       ( REGS_AXI_ARVALID       ) ,
    .REGS_AXI_ARREADY       ( REGS_AXI_ARREADY       ) ,
    .REGS_AXI_RDATA         ( REGS_AXI_RDATA         ) ,
    .REGS_AXI_RRESP         ( REGS_AXI_RRESP         ) ,
    .REGS_AXI_RVALID        ( REGS_AXI_RVALID        ) ,
    .REGS_AXI_RREADY        ( REGS_AXI_RREADY        ) ,

    .pix_cnt                ( pix_cnt                ) ,
    .menu_alpha             ( menu_alpha             ) ,
    .backlight_pwm_ctnr     ( backlight_pwm_ctnr     ) ,
    .disp_graym             ( disp_graym             ) ,
        
    .mm_disp_en             ( mm_disp_en             ) ,
    .mm_menu_en             ( mm_menu_en             ) ,
    .mm_bar_hide            ( mm_bar_hide            ) ,
    .touch_status           ( touch_status           ) ,
    .soft_pwr_off           ( soft_pwr_off           ) ,
    .force_pwr_off          ( force_pwr_off          ) ,
    .vga_pwr_off            ( vga_pwr_off            ) ,

    .xadc_init              ( xadc_init              ) ,
	.temp_value             ( temp_value             ) ,
	.vpin_value             ( vpin_value             ) ,
	.vtmp_value             ( vtmp_value             ) ,
	.vint_value             ( vint_value             ) ,
	.vaux_value             ( vaux_value             ) , 

    .fusion_push_state      ( fusion_push_state      ) ,
    .fusion_proc_state      ( fusion_proc_state      ) ,
    .fusion_base_x          ( fusion_base_x          ) ,
    .fusion_pix_black       ( fusion_pix_black       ) ,
    .fusion_push_ctrl       ( fusion_push_ctrl       ) ,
    .fusion_face_sens       ( fusion_face_sens       ) ,
    .fusion_edge_sens       ( fusion_edge_sens       ) ,
    .fusion_fast_l_x        ( fusion_fast_l_x        ) ,
    .fusion_slow_l_x        ( fusion_slow_l_x        ) ,
    .fusion_fast_r_x        ( fusion_fast_r_x        ) ,
    .fusion_slow_r_x        ( fusion_slow_r_x        ) ,
    .fusion_force_cfg       ( fusion_force_cfg       ) , 
    .fusion_time_cfg        ( fusion_time_cfg        ) ,
    
    .calibera_edge_x        ( calibera_edge_x        ) ,
    .calibera_edge_y        ( calibera_edge_y        ) ,   
    .engineer_edge_x        ( engineer_edge_x        ) ,
    .engineer_edge_y        ( engineer_edge_y        ) ,   
    .engineer_bright        ( engineer_bright        ) ,   
    
    .fiber_push_status      ( fiber_push_status      ) ,
    .fiber_aux_ctrl         ( fiber_aux_ctrl         ) ,
  
    .SDIO_0_wp              ( SDIO_0_wp              ) ,
    .video0_only            ( video0_only            ) ,
    .video1_only            ( video1_only            ) ,
    .video0_base_addr       ( video0_base_addr       ) ,
    .video1_base_addr       ( video1_base_addr       ) ,
    .menu_base_addr         ( menu_base_addr         ) ,

    .camera0_video_en       ( camera0_video_en       ) ,
    .camera0_dsp_ctrl       ( camera0_dsp_ctrl     ) ,
    .camera0_pwr_ctrl       ( camera0_pwr_ctrl       ) ,
    .camera0_ctrl           ( camera0_ctrl           ) ,
    .camera0_data_read      ( camera0_data_read      ) ,
    .camera0_trans_over     ( camera0_trans_over     ) ,
    .camera0_param          ( camera0_param          ) ,
    .camera0_error          ( camera0_error          ) , 
    .camera0_base_update    ( camera0_base_update    ) , 
    .camera0_base_addr      ( camera0_base_addr      ) ,
    .camera0_x_org_cnt      ( camera0_x_org_cnt      ) ,
    .camera0_y_org_cnt      ( camera0_y_org_cnt      ) ,
    .camera0_x_scaler       ( camera0_x_scaler       ) ,
    .camera0_y_scaler       ( camera0_y_scaler       ) ,
    .camera0_cfg_state      ( camera0_cfg_state      ) ,

    .camera1_video_en       ( camera1_video_en       ) ,
    .camera1_dsp_ctrl       ( camera1_dsp_ctrl       ) ,       
    .camera1_pwr_ctrl       ( camera1_pwr_ctrl       ) ,
    .camera1_ctrl           ( camera1_ctrl           ) ,
    .camera1_data_read      ( camera1_data_read      ) ,
    .camera1_trans_over     ( camera1_trans_over     ) ,
    .camera1_param          ( camera1_param          ) ,
    .camera1_error          ( camera1_error          ) ,    
    .camera1_base_update    ( camera1_base_update    ) , 
    .camera1_base_addr      ( camera1_base_addr      ) ,
    .camera1_x_org_cnt      ( camera1_x_org_cnt      ) ,
    .camera1_y_org_cnt      ( camera1_y_org_cnt      ) ,
    .camera1_x_scaler       ( camera1_x_scaler       ) ,
    .camera1_y_scaler       ( camera1_y_scaler       ) ,
    .camera1_cfg_state      ( camera1_cfg_state      ) ,

    .motor_speed            ( motor_speed            ) ,
    .motor_ctrl_l           ( motor_ctrl_l           ) ,
    .motor_ctrl_r           ( motor_ctrl_r           ) ,
    .motor_ctrl_x           ( motor_ctrl_x           ) ,
    .motor_ctrl_y           ( motor_ctrl_y           ) ,
    .gaoya_time             ( gaoya_time             ) ,
    .gaoya_force            ( gaoya_force            ) ,
    .heat_mode              ( heat_mode              ) ,
    .heat_status            ( heat_status            ) ,
    .heat_speed             ( heat_speed             ) ,
    .heat_time              ( heat_time              ) ,
    .heat_test              ( heat_test              ) ,
    .beep_cntr              ( beep_cntr              ) ,
    .tone_divider           ( tone_divider           ) ,

    .rtc_ctrl               ( rtc_ctrl               ) ,
    .rtc_data_read          ( rtc_data_read          ) ,
    .rtc_trans_over         ( rtc_trans_over         ) ,
    .load_time              ( load_time              ) ,
    .pcf8563_date           ( pcf8563_date           ) ,
    .pcf8563_time           ( pcf8563_time           ) ,
    .local_date             ( local_date             ) ,
    .local_time             ( local_time             ) ,
    .data_flow_err          ( data_flow_err          ) ,
    
    .pwr_touch              ( pwr_touch              ) ,
    .plh_keys               ( plh_keys               ) ,
    .func_keys              ( func_keys              ) ,
        
    .hardware_version       ( hardware_version       ) ,

    .cpu_mem_addrb          ( cpu_mem_addrb          ) ,
    .cpu_mem_doutb          ( cpu_mem_doutb          ) ,
    .cpu_mem_ready0         ( cpu_mem_ready0         ) ,
    .cpu_mem_ready1         ( cpu_mem_ready1         )           
);
//--------------------------------------------------------
VDMA_WRAPPER #(
    .C_M_AXI_BURST_LEN    ( C_M_AXI_BURST_LEN     ),
    .C_M_AXI_ID_WIDTH     ( C_M_AXI_ID_WIDTH      ),
    .C_M_AXI_ADDR_WIDTH   ( C_M_AXI_ADDR_WIDTH    ),
    .C_M_AXI_DATA_WIDTH   ( C_M_AXI_DATA_WIDTH    ),
    .C_M_AXI_AWUSER_WIDTH ( C_M_AXI_AWUSER_WIDTH  ),
    .C_M_AXI_ARUSER_WIDTH ( C_M_AXI_ARUSER_WIDTH  ),
    .C_M_AXI_WUSER_WIDTH  ( C_M_AXI_WUSER_WIDTH   ),
    .C_M_AXI_RUSER_WIDTH  ( C_M_AXI_RUSER_WIDTH   ),
    .C_M_AXI_BUSER_WIDTH  ( C_M_AXI_BUSER_WIDTH   )
)VDMA_WRAPPER_inst0( 
    .CAMERA_AXI_ACLK      ( CAMERA_AXI_ACLK       ) ,
    .CAMERA_AXI_ARESETN   ( CAMERA_AXI_ARESETN    ) ,

    .CAMERA_AXI_AWID      ( CAMERA_AXI_AWID       ) ,
    .CAMERA_AXI_AWADDR    ( CAMERA_AXI_AWADDR     ) ,
    .CAMERA_AXI_AWLEN     ( CAMERA_AXI_AWLEN      ) ,
    .CAMERA_AXI_AWSIZE    ( CAMERA_AXI_AWSIZE     ) ,
    .CAMERA_AXI_AWBURST   ( CAMERA_AXI_AWBURST    ) ,
    .CAMERA_AXI_AWLOCK    ( CAMERA_AXI_AWLOCK     ) ,
    .CAMERA_AXI_AWCACHE   ( CAMERA_AXI_AWCACHE    ) ,
    .CAMERA_AXI_AWPROT    ( CAMERA_AXI_AWPROT     ) ,
    .CAMERA_AXI_AWQOS     ( CAMERA_AXI_AWQOS      ) ,
    .CAMERA_AXI_AWUSER    ( CAMERA_AXI_AWUSER     ) ,
    .CAMERA_AXI_AWVALID   ( CAMERA_AXI_AWVALID    ) ,
    .CAMERA_AXI_AWREADY   ( CAMERA_AXI_AWREADY    ) ,
    .CAMERA_AXI_WDATA     ( CAMERA_AXI_WDATA      ) ,
    .CAMERA_AXI_WSTRB     ( CAMERA_AXI_WSTRB      ) ,
    .CAMERA_AXI_WLAST     ( CAMERA_AXI_WLAST      ) ,
    .CAMERA_AXI_WUSER     ( CAMERA_AXI_WUSER      ) ,
    .CAMERA_AXI_WVALID    ( CAMERA_AXI_WVALID     ) ,
    .CAMERA_AXI_WREADY    ( CAMERA_AXI_WREADY     ) ,
    .CAMERA_AXI_BID       ( CAMERA_AXI_BID        ) ,
    .CAMERA_AXI_BRESP     ( CAMERA_AXI_BRESP      ) ,
    .CAMERA_AXI_BUSER     ( CAMERA_AXI_BUSER      ) ,
    .CAMERA_AXI_BVALID    ( CAMERA_AXI_BVALID     ) ,
    .CAMERA_AXI_BREADY    ( CAMERA_AXI_BREADY     ) ,

    .video0_only          ( video0_only           ) ,
    .video1_only          ( video1_only           ) ,
    .videos_flow_err      ( data_flow_err[15:8]   ) ,

    .camera0_video_en     ( camera0_video_en      ) ,
    .camera0_base_addr    ( camera0_base_addr     ) ,
    .camera0_base_update  ( camera0_base_update   ) ,

    .camera1_video_en     ( camera1_video_en      ) ,
    .camera1_base_addr    ( camera1_base_addr     ) ,
    .camera1_base_update  ( camera1_base_update   ) ,

    .camera0_wr_en        ( camera0_wr_en         ) ,
    .camera0_din          ( camera0_din           ) ,

    .camera1_wr_en        ( camera1_wr_en         ) ,
    .camera1_din          ( camera1_din           ) 
);
//--------------------------------------------------------
CAMERA_WRAPPER CAMERA_WRAPPER_inst0(  
    .clk_100mhz           ( clk_100mhz            ) ,
    .resetn               ( c_resetn              ) ,

    .camera_pwr_ctrl      ( camera0_pwr_ctrl      ) ,
    .camera_dsp_ctrl      ( camera0_dsp_ctrl      ) ,
    .camera_ctrl          ( camera0_ctrl          ) ,
    .camera_data_read     ( camera0_data_read     ) ,
    .camera_trans_over    ( camera0_trans_over    ) ,

    .camera_x_org_cnt     ( camera0_x_org_cnt     ) ,
    .camera_y_org_cnt     ( camera0_y_org_cnt     ) ,
    .camera_x_scaler      ( camera0_x_scaler      ) ,
    .camera_y_scaler      ( camera0_y_scaler      ) ,
    .camera_pix_black     ( fusion_pix_black      ) ,
    .camera_bright        ( engineer_bright[7:0]  ) ,   
    .camera_param         ( camera0_param         ) ,
    .camera_error         ( camera0_error         ) , 
    .camera_video_en      ( camera0_video_en      ) ,       
    .camera_pclk          ( camera0_pclk          ) ,
    .camera_yuv           ( camera0_yuv           ) ,
    .camera_h_sync        ( camera0_h_sync        ) ,
    .camera_v_sync        ( camera0_v_sync        ) ,
    .camera_pwrdown       ( camera0_pwrdown       ) ,
    .camera_resetn        ( camera0_resetn        ) ,

    .camera_sclk          ( camera0_sclk          ) ,
    .camera_sda           ( camera0_sda           ) ,

    .rom_cfgAddr          ( camera0_cfgAddr       ) ,
    .rom_cfgData          ( camera0_cfgData       ) ,   
    .ext_cfg_state        ( camera0_cfg_state     ) ,   
	
    .camera_wr_en         ( camera0_wr_en         ) ,
    .camera_din           ( camera0_din           ) ,
    
    .coproc_wr_en         ( coproc0_wr_en         ) ,
    .coproc_din           ( coproc0_din           )             
);
//--------------------------------------------------------
CAMERA_WRAPPER CAMERA_WRAPPER_inst1(  
    .clk_100mhz           ( clk_100mhz            ) ,
    .resetn               ( c_resetn              ) ,

    .camera_pwr_ctrl      ( camera1_pwr_ctrl      ) ,
    .camera_dsp_ctrl      ( camera1_dsp_ctrl      ) ,
    .camera_ctrl          ( camera1_ctrl          ) ,
    .camera_data_read     ( camera1_data_read     ) ,
    .camera_trans_over    ( camera1_trans_over    ) ,

    .camera_x_org_cnt     ( camera1_x_org_cnt     ) ,
    .camera_y_org_cnt     ( camera1_y_org_cnt     ) ,
    .camera_x_scaler      ( camera1_x_scaler      ) ,
    .camera_y_scaler      ( camera1_y_scaler      ) ,
    .camera_pix_black     ( fusion_pix_black      ) ,
    .camera_bright        ( engineer_bright[23:16]) ,   

    .camera_param         ( camera1_param         ) ,
    .camera_error         ( camera1_error         ) , 
    .camera_video_en      ( camera1_video_en      ) ,   
    .camera_pclk          ( camera1_pclk          ) ,
    .camera_yuv           ( camera1_yuv           ) ,
    .camera_h_sync        ( camera1_h_sync        ) ,
    .camera_v_sync        ( camera1_v_sync        ) ,
    .camera_pwrdown       ( camera1_pwrdown       ) ,
    .camera_resetn        ( camera1_resetn        ) ,

    .camera_sclk          ( camera1_sclk          ) ,
    .camera_sda           ( camera1_sda           ) ,

    .rom_cfgAddr          ( camera1_cfgAddr       ) ,
    .rom_cfgData          ( camera1_cfgData       ) ,   
    .ext_cfg_state        ( camera1_cfg_state     ) ,      	

    .camera_wr_en         ( camera1_wr_en         ) ,
    .camera_din           ( camera1_din           ) ,

    .coproc_wr_en         ( coproc1_wr_en         ) ,
    .coproc_din           ( coproc1_din           )     
);   
//--------------------------------------------------------
VGA_WRAPPER #(
    .C_M_AXI_BURST_LEN    ( C_M_AXI_BURST_LEN      ),
    .C_M_AXI_ID_WIDTH     ( C_M_AXI_ID_WIDTH       ),
    .C_M_AXI_ADDR_WIDTH   ( C_M_AXI_ADDR_WIDTH     ),
    .C_M_AXI_DATA_WIDTH   ( C_M_AXI_DATA_WIDTH     ),
    .C_M_AXI_AWUSER_WIDTH ( C_M_AXI_AWUSER_WIDTH   ),
    .C_M_AXI_ARUSER_WIDTH ( C_M_AXI_ARUSER_WIDTH   ),
    .C_M_AXI_WUSER_WIDTH  ( C_M_AXI_WUSER_WIDTH    ),
    .C_M_AXI_RUSER_WIDTH  ( C_M_AXI_RUSER_WIDTH    ),
    .C_M_AXI_BUSER_WIDTH  ( C_M_AXI_BUSER_WIDTH    )
)VGA_WRAPPER_inst0( 
    .VGA_AXI_ACLK    ( VGA_AXI_ACLK       ) ,
    .VGA_AXI_ARESETN ( VGA_AXI_ARESETN    ) ,

    .VGA_AXI_ARID    ( VGA_AXI_ARID       ) ,
    .VGA_AXI_ARADDR  ( VGA_AXI_ARADDR     ) ,
    .VGA_AXI_ARLEN   ( VGA_AXI_ARLEN      ) ,
    .VGA_AXI_ARSIZE  ( VGA_AXI_ARSIZE     ) ,
    .VGA_AXI_ARBURST ( VGA_AXI_ARBURST    ) ,
    .VGA_AXI_ARLOCK  ( VGA_AXI_ARLOCK     ) ,
    .VGA_AXI_ARCACHE ( VGA_AXI_ARCACHE    ) ,
    .VGA_AXI_ARPROT  ( VGA_AXI_ARPROT     ) ,
    .VGA_AXI_ARQOS   ( VGA_AXI_ARQOS      ) ,
    .VGA_AXI_ARUSER  ( VGA_AXI_ARUSER     ) ,
    .VGA_AXI_ARVALID ( VGA_AXI_ARVALID    ) ,
    .VGA_AXI_ARREADY ( VGA_AXI_ARREADY    ) ,
    .VGA_AXI_RID     ( VGA_AXI_RID        ) ,
    .VGA_AXI_RDATA   ( VGA_AXI_RDATA      ) ,
    .VGA_AXI_RRESP   ( VGA_AXI_RRESP      ) ,
    .VGA_AXI_RLAST   ( VGA_AXI_RLAST      ) ,
    .VGA_AXI_RUSER   ( VGA_AXI_RUSER      ) ,
    .VGA_AXI_RVALID  ( VGA_AXI_RVALID     ) ,
    .VGA_AXI_RREADY  ( VGA_AXI_RREADY     ) ,

    .clk_25mhz       ( clk_25mhz          ) ,
    .clk_175mhz      ( pl_175mhz          ) ,
    .resetn          ( a25m_resetn        ) ,

    .video0_only     ( video0_only        ) ,
    .video1_only     ( video1_only        ) ,
    .video0_base_addr( video0_base_addr   ) ,
    .video1_base_addr( video1_base_addr   ) ,
    .menu_base_addr  ( menu_base_addr     ) ,
    .pix_cnt         ( pix_cnt            ) ,
    .menu_alpha      ( menu_alpha         ) ,
    .disp_graym      ( disp_graym         ) ,
    .backlight_pwm   ( backlight_pwm      ) ,
    .backlight_pwm_ctnr   ( backlight_pwm_ctnr   ) ,
        
    .R               ( R                  ) ,
    .G               ( G                  ) ,
    .B               ( B                  ) ,
    .vga_pclk        ( vga_pclk           ) ,
    .vga_h_sync      ( vga_h_sync         ) ,
    .vga_v_sync      ( vga_v_sync         ) ,
    .vga_de          ( vga_de             ) ,

    .mm_bar_hide     ( mm_bar_hide        ) ,
    .mm_menu_en      ( mm_menu_en         ) ,
    .mm_disp_en      ( mm_disp_en         ) ,

    .data_flow_err   ( data_flow_err[7:0] )
); 
//--------------------------------------------------------
CO_PROCESSOR_WRAPPER CO_PROCESSOR_WRAPPER_inst0( 
    .clk_100mhz         ( clk_100mhz         ) ,
    .resetn             ( resetn             ) ,

    .camera0_x_org_cnt  ( camera0_x_org_cnt  ) ,
    .camera0_y_org_cnt  ( camera0_y_org_cnt  ) ,
    .camera1_x_org_cnt  ( camera1_x_org_cnt  ) ,
    .camera1_y_org_cnt  ( camera1_y_org_cnt  ) ,

    .touch_status       ( touch_status       ) ,
    .fusion_push_state  ( fusion_push_state  ) ,
    .fusion_proc_state  ( fusion_proc_state  ) ,
    .fusion_base_x      ( fusion_base_x      ) ,
    .fusion_pix_black   ( fusion_pix_black   ) ,
    .fusion_push_ctrl   ( fusion_push_ctrl   ) ,
    .fusion_face_sens   ( fusion_face_sens   ) ,
    .fusion_edge_sens   ( fusion_edge_sens   ) ,
    .fusion_fast_l_x    ( fusion_fast_l_x    ) ,
    .fusion_slow_l_x    ( fusion_slow_l_x    ) ,
    .fusion_fast_r_x    ( fusion_fast_r_x    ) ,
    .fusion_slow_r_x    ( fusion_slow_r_x    ) ,
    .fusion_force_cfg   ( fusion_force_cfg   ) , 
    .fusion_time_cfg    ( fusion_time_cfg    ) ,
    .fusion_proc_intr   ( fusion_proc_intr   ) ,
    
    .fiber_push_status  ( fiber_push_status  ) ,
    .fiber_aux_ctrl     ( fiber_aux_ctrl     ) ,
 
	.force_pause_l      ( force_pause_l      ) ,
	.force_pause_r      ( force_pause_r      ) ,

    .gaoya_ctrl_time    ( gaoya_ctrl_time    ) ,
    .gaoya_ctrl_force   ( gaoya_ctrl_force   ) ,    

    .motor_move_l       ( motor_move_l       ) ,
    .motor_move_r       ( motor_move_r       ) ,
 
    .coproc0_wr_en      ( coproc0_wr_en      ) ,
    .coproc0_din        ( coproc0_din        ) ,

    .coproc1_wr_en      ( coproc1_wr_en      ) ,
    .coproc1_din        ( coproc1_din        ) ,

    .calibera_edge_x    ( calibera_edge_x    ) ,
    .calibera_edge_y    ( calibera_edge_y    ) ,       
    .engineer_edge_x    ( engineer_edge_x    ) ,
    .engineer_edge_y    ( engineer_edge_y    ) ,   
     
    .cpu_mem_addrb      ( cpu_mem_addrb      ) ,
    .cpu_mem_doutb      ( cpu_mem_doutb      ) ,
    .cpu_mem_ready0     ( cpu_mem_ready0     ) ,
    .cpu_mem_ready1     ( cpu_mem_ready1     )         
); 
//--------------------------------------------------------
MOTOR_WRAPPER MOTOR_WRAPPER_inst0(
    .clk_30k         ( slow_clk30k_out ) ,
    .reset_n         ( resetn          ) ,

    .motor_speed     ( motor_speed     ) ,
    .motor_ctrl_l    ( motor_ctrl_l    ) ,
    .motor_ctrl_r    ( motor_ctrl_r    ) ,
    .motor_ctrl_x    ( motor_ctrl_x    ) ,
    .motor_ctrl_y    ( motor_ctrl_y    ) ,

	.force_pause_l   ( force_pause_l   ) ,
	.force_pause_r   ( force_pause_r   ) ,
	
    .motor_move_l    ( motor_move_l    ) ,
    .motor_move_r    ( motor_move_r    ) ,

    .phase_l         ( phase_l         ) ,
    .phase_r         ( phase_r         ) ,
    .phase_x         ( phase_x         ) ,
    .phase_y         ( phase_y         ) 
);
//--------------------------------------------------------
ACCESSORY_WRAPPER ACCESSORY_WRAPPER_inst0( 
    .clk_25mhz         ( clk_25mhz         ) ,
    .clk_100mhz        ( clk_100mhz        ) ,
    .resetn            ( resetn            ) ,

    .pl_clk            ( pl_clk            ) ,
    .soft_pwr_off      ( soft_pwr_off      ) ,
    .pwr_ctrl          ( pwr_ctrl          ) ,
    .force_pwr_off     ( force_pwr_off     ) ,
    
    .xadc_init         ( xadc_init         ) ,
    .vp_in             ( vp_in             ) ,
    .vn_in             ( vn_in             ) ,
    .tp_in             ( tp_in             ) ,
    .tn_in             ( tn_in             ) ,    
	.temp_value        ( temp_value        ) ,
	.vpin_value        ( vpin_value        ) ,
	.vtmp_value        ( vtmp_value        ) ,
	.vint_value        ( vint_value        ) ,
	.vaux_value        ( vaux_value        ) , 

    .slow_clk30k_out   ( slow_clk30k_out   ) ,
    
    .pwr_touch         ( pwr_touch         ) ,    
    .pl_keys           ( pl_keys           ) ,
    .plh_keys          ( plh_keys          ) , 
    .key_intr          ( key_intr          ) ,
         
    .gaoya_time        ( gaoya_time        ) ,
    .gaoya_force       ( gaoya_force       ) ,
    .gaoya_ctrl_time   ( gaoya_ctrl_time   ) ,
    .gaoya_ctrl_force  ( gaoya_ctrl_force  ) ,    
    .dac_sclk          ( dac_sclk          ) ,
    .dac_sdata         ( dac_sdata         ) ,
    .dac_load          ( dac_load          ) ,
    .gaoya             ( gaoya             ) ,
    .func_keys         ( func_keys         ) , 
    .heat_mode         ( heat_mode         ) ,
    .heat_status       ( heat_status       ) ,
    .heat_speed        ( heat_speed        ) ,
    .heat_time         ( heat_time         ) ,
    .heat_touch        ( heat_touch        ) ,
    .heat_test         ( heat_test         ) ,
    .hall_touch        ( hall_touch        ) ,
    .posl_touch        ( posl_touch        ) ,
    .posr_touch        ( posr_touch        ) ,
    .touch_status      ( touch_status      ) ,
    .heat              ( heat              ) ,
    .heat_ledon        ( heat_ledon        ) ,
    .beep_cntr         ( beep_cntr         ) ,
    .tone_divider      ( tone_divider      ) ,
    .beep              ( beep              ) ,
    .rtc_ctrl          ( rtc_ctrl          ) ,
    .rtc_data_read     ( rtc_data_read     ) ,
    .rtc_trans_over    ( rtc_trans_over    ) ,
    .rtc_scl           ( rtc_scl           ) ,
    .rtc_sda           ( rtc_sda           ) ,
    .load_time         ( load_time         ) ,
    .pcf8563_date      ( pcf8563_date      ) ,
    .pcf8563_time      ( pcf8563_time      ) ,
    .local_date        ( local_date        ) ,
    .local_time        ( local_time        ) 
);

endmodule
